package com.herui.iot.data;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;


/**
 * Created by amanda.shan on 2019/7/22.
 */
public class CustomFuture {

    private final long beginTimestamp = System.currentTimeMillis();
    private final CountDownLatch countDownLatch = new CountDownLatch(1);

    private final AtomicBoolean executeCallbackOnlyOnce = new AtomicBoolean(false);
    private volatile boolean sendRequestOK = true;
    private volatile Throwable cause;

    private boolean sucess;

    public boolean waitResponse(final long timeoutMillis) throws InterruptedException {
        this.countDownLatch.await(timeoutMillis, TimeUnit.MILLISECONDS);
        return this.sucess;
    }

    public void putResponse(final Boolean sucess) {
        this.sucess = sucess;
        this.countDownLatch.countDown();
    }

    public void release() {

    }
}
